﻿using UnityEngine;
using System.Collections;


public class BindData<T>{
	public event System.Action<T,T> onVlaueChange;
	T _value;
	public T Value{
		get{ 
			return _value;
		}
		set{ 
			if (!object.Equals(_value,value)){
				T oldvalue = _value;
				_value = value;
				ValueChange (oldvalue, _value);
			}
		}
	}	

	void ValueChange(T oldvalue,T newvalue){
		if(onVlaueChange != null)
			onVlaueChange (oldvalue, newvalue);
	}

	public override string ToString ()
	{
		return (Value != null ? Value.ToString () : "null");
	}

}

public abstract class MyMode{
}


public abstract class ViewMode<T,TView>where T:MyMode,new() where TView:ViewUI{
	public BindData<T> mymodel = new BindData<T>();
	protected TView View;


	public ViewMode(){
		mymodel.Value = new T ();
	}

	public virtual void BindView(ViewUI view){
		this.View = (TView)view;
	}
}

public class MyView:MonoBehaviour{
	public System.Action<string> onClick;
	public UILabel label;
	public void OnNameChange(string oldname,string newname){
		label.text = newname;
	}

	public void OnClick(){
		onClick ("aa");
	}
}